package com.javacode2018.lesson001.demo3;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;

/**
 * @Author: hongsir
 * @Date: 2024/10/9 - 10 - 09 - 17:08
 * @Description: com.javacode2018.lesson001.demo3
 * @Version: 1.0
 */
public class UserFactoryBean implements FactoryBean<UserModel> {
    int count = 1;

    @Nullable
    @Override
    public UserModel getObject() throws Exception { //@1
        UserModel userModel = new UserModel();
        userModel.setName("我是通过FactoryBean创建的第"+ count++ + "对象");//@4
        return userModel;
    }

    @Nullable
    @Override
    public Class<?> getObjectType() {
        return UserModel.class; //@2
    }

    @Override
    public boolean isSingleton() {
        return true; //@3
//        return false; //@3
    }
}
